package com.ruoyi.proposals.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.proposals.domain.ProComment;
import com.ruoyi.proposals.domain.ProFavorite;
import com.ruoyi.proposals.domain.ProProposals;
import com.ruoyi.proposals.mapper.ProProposalsMapper;
import com.ruoyi.proposals.service.ProProposalsService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class ProProposalsServiceImpl extends ServiceImpl<ProProposalsMapper, ProProposals> implements ProProposalsService {

    @Override
    public List<ProProposals> selectList(ProProposals proposals) {
        return baseMapper.queryList(proposals);
    }

    @Override
    public void deleteByIds(Long[] ids) {
        baseMapper.deleteByIds(Arrays.asList(ids));
    }

    @Override
    public List<ProProposals> selectByUserId(ProProposals proposals) {
        return baseMapper.selectByUserId(proposals.getUserId());
    }

    @Override
    public ProProposals getProposalDetail(Long proposalId) {
        if (proposalId != null) {
            return baseMapper.selectByProposalId(proposalId);
        }
        return null;
    }

    @Override
    public List<ProProposals> getFavoritesByUserId(Long userId) {
        return baseMapper.getFavoritesByUserId(userId);
    }

    @Override
    public boolean favoriteProposal(ProFavorite proFavorite) {
        if (proFavorite.getProposalId() != null && proFavorite.getUserId()!= null){
            return baseMapper.favoriteProposal(proFavorite);
        }
        return false;
    }

    @Override
    public boolean commentProposal(ProComment proComment) {
        if  (proComment.getProposalId() != null && proComment.getUserId()!= null && proComment.getComment() != null){
            return baseMapper.commentProposal(proComment);
        }
        return false;
    }


}




